package com.liwen.service.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 *  线程池配置
 */
@Configuration
public class ExecutorConfig extends AppConfig {
    /**
     * 获取前缀
     *
     * @return
     */
    @Override
    protected String prefix() {
        return "executor.";
    }

    @Bean
    public TaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(getInt("core-pool-size"));
        executor.setKeepAliveSeconds(getInt("keep-alive-seconds"));
        executor.setMaxPoolSize(getInt("max-pool-size"));
        executor.setQueueCapacity(getInt("queue-capacity"));
        return executor;
    }
}
